package com.base.monitor.admin.controller.manage;

import com.base.monitor.model.model.biz.cfg.vo.IndicatorVo;
import com.base.monitor.model.model.system.entity.User;
import com.base.monitor.module.biz.service.cfg.IndicatorService;
import com.base.monitor.module.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @description: 模态框数据加载控制器
 * @author: tsing
 * @create: 2021-03-04 21:56
 */
@Controller
@RequestMapping("/load")
public class LoadController {

    @Autowired
    private UserService userService;

    @Autowired
    private IndicatorService indicatorService;

    /**
     * 加载用户详情模态框
     * @param model 模型对象
     * @param id 用户id
     * @return
     */
    @GetMapping("/user/{id}")
    public String user(Model model, @PathVariable("id") Long id) {
        User user = userService.findOne(id);
        model.addAttribute("user", user);
        return "/user/form";
    }

    /**
     * 加载指标详情模态框
     * @param model 模型对象
     * @param id 指标id
     * @return
     */
    @GetMapping("/indicator/{id}")
    public String indicator(Model model, @PathVariable("id") String id) {
        IndicatorVo vo = indicatorService.findOne(id);
        model.addAttribute("indicator", vo);
        return "/indicator/form";
    }
}
